//
//  NotLoginHeaderView.swift
//  maopu
//
//  Created by xiongsh on 2017/5/2.
//  Copyright © 2017年 maopu. All rights reserved.
//

import UIKit
public protocol NotLoginHeaderViewDelegate : NSObjectProtocol {
    func notLoginBtnSignClick()
}
class NotLoginHeaderView: UIView {

    fileprivate var btnSign: UIButton!  // 打卡
    fileprivate var btnUserhead: UIButton! //头像
    fileprivate var labelGoLogin: UILabel!
    fileprivate var userRelationToolView: UserRelationToolView! //获赞、关注、粉丝、我的资料
    weak open var delegate: NotLoginHeaderViewDelegate?
    /*
     // Only override draw() if you perform custom drawing.
     // An empty implementation adversely affects performance during animation.
     override func draw(_ rect: CGRect) {
     // Drawing code
     }
     */
    override init(frame: CGRect) {
        super.init(frame: frame)
        self.initView()
    }
    
    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    fileprivate func initView() {
        
        let left: CGFloat = 15.0
        var top: CGFloat = 14.0
        let userHeadLength: CGFloat = 60.0
        let userRelationToolViewHeight: CGFloat = 60.0
        
        self.btnSign = UIButton.init(frame: CGRect.init(x: AppWidth - left - 53, y: top, width: 53.0, height: 25.0))
        self.btnSign.setBackgroundImage(UIImage.createImageWithColor(color: UIColor.colorWithHexString(hex: "#ffce54")), for: .normal)
        self.btnSign.setBackgroundImage(UIImage.createImageWithColor(color: UIColor.colorWithHexString(hex: "#dcb34c")), for: .highlighted)
        self.btnSign.setTitle("打卡", for: .normal)
        self.btnSign.setCornerRadius(radius: 12.5)
        self.btnSign.titleLabel?.font = UIFont.LightDefaultFont(11.0)
        self.btnSign.setTitleColor(UIColor.black, for: .normal)
        self.btnSign.addTarget(self, action: #selector(btnSignClick), for: .touchUpInside)
        self.addSubview(self.btnSign)
        top += 25.0 + 20.0
        
        self.btnUserhead = UIButton.init(frame: CGRect.init(x: (AppWidth - userHeadLength)/2, y: top, width: userHeadLength, height: userHeadLength))
        self.btnUserhead.sd_setBackgroundImage(with: URL.init(string: "https://imgsa.baidu.com/baike/w%3D268/sign=b27b65b7014f78f0800b9df541300a83/267f9e2f0708283856a627f7ba99a9014d08f1ae.jpg"), for: .normal, placeholderImage: UIImage.createImageWithColor(color: UIColor.colorWithHexString(hex: "#ff0000")))
        self.btnUserhead.setCircel()
        self.addSubview(self.btnUserhead)
        top += userHeadLength + 10.0
        
        self.labelGoLogin = UILabel.init(frame: CGRect.init(x: 0, y: top, width: AppWidth, height: 30))
        self.labelGoLogin.font = UIFont.systemFont(ofSize:15.0)
        self.labelGoLogin.textColor = UIColor.black
        self.labelGoLogin.textAlignment = .center
        self.labelGoLogin.text = "请点击登录"
        self.addSubview(self.labelGoLogin)
        
        top = self.height() - userRelationToolViewHeight
        self.userRelationToolView = UserRelationToolView.init(frame: CGRect.init(x: 0, y: top, width: AppWidth, height: userRelationToolViewHeight))
        self.addSubview(self.userRelationToolView)
        
    }
    @objc func btnSignClick() {
//        self.delegate?.responds(to: <#T##Selector!#>)
        self.delegate?.notLoginBtnSignClick()
    }
}
